@extends('layouts.app')

@section('content')
    <h1>任务列表</h1>
    <a href="{{ route('tasks.create') }}">添加新任务</a>
    @if ($tasks->isEmpty())
        <p>暂无任务</p>
    @else
        <table>
            <tr>
                <th>标题</th>
                <th>描述</th>
                <th>操作</th>
            </tr>
            @foreach ($tasks as $task)
                <tr>
                    <td>{{ $task->title }}</td>
                    <td>{{ $task->description ?? '无描述' }}</td>
                    <td>
                        <a href="{{ route('tasks.edit', $task) }}">编辑</a>
                        <form action="{{ route('tasks.destroy', $task) }}" method="POST" style="display:inline;">
                            @csrf
                            @method('DELETE')
                            <button type="submit" onclick="return confirm('确定删除吗？')">删除</button>
                        </form>
                    </td>
                </tr>
            @endforeach
        </table>
    @endif
@endsection